package com.example.dell.newstart.base;

import com.example.dell.newstart.bean.CartList;
import com.example.dell.newstart.bean.MyPageInfo;
import com.example.dell.newstart.bean.Product;

import java.util.Map;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

/**
 * created by Dongkai on 2018/12/5
 */

public class RequestInterface {
    /**
     * 后台url ip地址
     */
    public static final String baseIp = "120.77.253.51";
    /**
     * 后台url地址
     */
    public static final String basePath = "http://" + baseIp + ":8080/SweetHouse/";

    public static final String baseImgPath = "http://" + baseIp + ":8080/SweetHouse/Images/";

    //登陆接口，使用Gson解析，也是请求单个数据的示例
    public interface Login3 {
        @POST("user/login")
        @FormUrlEncoded
        Call<ServerResponse<com.example.dell.newstart.bean.User>> login(@Field("username") String userName,
                                                                        @Field("password") String password);
    }

    //以原生方式获取返回结果，不用Gson解析（在Gson解析出错的情况下，获取返回的数据进行操作（看是哪一项数据解析不了，已知Date类型不行））
    public interface Login2 {
        @POST("login.do")
        @FormUrlEncoded
        Call<ResponseBody> login(@Field("username") String userName, @Field("password") String password);
    }

    public interface User {
        //注册
        @POST("user/register")
        @FormUrlEncoded
        Call<ServerResponse> register(@Field("username") String userName,
                                      @Field("password") String password,
                                      @Field("email") String email,
                                      @Field("phone") String phone);

    }

    public interface getProductsList {
        @POST("product/list.do")
        @FormUrlEncoded
        Call<ServerResponse<Product>> getProducts(@FieldMap Map<String, String> params);
    }


    //请求数据集合的接口，使用Gson解析，其中ServerResponse<T>中的T保持和后台Controller中对应的方法保持一致
    public interface getProductsList2 {
        @POST("product/list")
        @FormUrlEncoded
        Call<ServerResponse<MyPageInfo<Product>>> getProducts(@Field("keyword") String keyword,
                                                              @Field("categoryId") Integer categoryId,
                                                              @Field("pageNum") int pageNum,
                                                              @Field("pageSize") int pageSize,
                                                              @Field("orderBy") String orderBy);
    }

    //登录状态更新个人信息接口
    public interface UpdateUserInfo {
        @POST("user/update_information.do")
        @FormUrlEncoded
        Call<ServerResponse<User>> update(@Field("email") String email, @Field("phone") String phone, @Field("question") String question, @Field("answer") String answer);
    }

    //忘记密码
    public interface ForgetPassword {
        @POST("user/forget_get_question.do")
        @FormUrlEncoded
        Call<ResponseBody> findBack(@Field("username") String username);
    }

    //登录状态更新个人信息接口(因为返回值不是一个对象，那么不用解析)
    public interface Register {
        @POST("user/register.do")
        @FormUrlEncoded
        Call<ServerResponse> register(@Field("username") String userName, @Field("password") String password,  @Field("phone") String phone);
    }

    //登录状态更新个人信息接口(尝试解析)
    public interface Register2 {
        @POST("user/register.do")
        @FormUrlEncoded
        Call<ServerResponse> register2(@Field("username") String userName, @Field("password") String password, @Field("email") String email, @Field("phone") String phone, @Field("question") String question, @Field("answer") String answer);
    }

    //登录状态更新个人信息接口(尝试解析)
    public interface Address {
        @POST("shipping/add.do")
        @FormUrlEncoded
        Call<ServerResponse> add(@Field("userId") int userId,
                                 @Field("receiverName") String receiverName,
                                 @Field("receiverPhone") String receiverPhone,
                                 @Field("receiverMobile") String receiverMobile,
                                 @Field("receiverProvince") String receiverProvince,
                                 @Field("receiverCity") String receiverCity,
                                 @Field("receiverAddress") String receiverAddress,
                                 @Field("receiverZip") String receiverZip
        );

        @POST("shipping/list.do")
        @FormUrlEncoded
        Call<ServerResponse<MyPageInfo>> getAddressList(@Field("pageNum") int pageNum,
                                                        @Field("pageSize") int pageSize);

    }
    //购物车List列表
    public interface Cart {
        @POST("cart/list")
        @FormUrlEncoded
        Call<ServerResponse<CartList>> getCartList(@Field("userId") Integer userId);

        //购物车添加商品
        @POST("cart/add")
        @FormUrlEncoded
        Call<ServerResponse<CartList>> add(@Field("productId") int productId,
                                           @Field("count") int count,
                                           @Field("userId") Integer userId);

        //更新购物车商品数量
        @POST("cart/update")
        @FormUrlEncoded
        Call<ServerResponse<CartList>> update(@Field("productId") int productId,
                                              @Field("count") int count,
                                              @Field("userId") Integer userId);

        //删除购物车商品
        @POST("cart/delete_product")
        @FormUrlEncoded
        Call<ServerResponse<CartList>> delete(@Field("productId") int productId,
                                              @Field("userId") int userId);
    }

}
